package com.example.kotlindemo.demo

/**
 * Author 87231
 * 2022/8/17 22:43
 *
 * Unit0
 * describe：
 **/
class Unit0 {

    fun test(arr: Array<Int>): Array<Int> {
        var start = System.currentTimeMillis()
//        for (i in arr.indices) {
//            for (j in 0 until arr.size - 1) {
//                if (arr[i] > arr[j]) {
//                    val a = arr[j]
//                    arr[j] = arr[i]
//                    arr[i] = a
//                }
//
//            }
//        }
        for (i in arr.indices) {
            for (j in 0 until arr.size - 1) {
                if (arr[j] > arr[j + 1]) {
                    var tmp = 0
                    tmp = arr[j]
                    arr[j] = arr[j + 1]
                    arr[j + 1] = tmp
                }
            }
        }

        var sum = System.currentTimeMillis() - start
        println("sum = $sum")
        return arr
    }

}